﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace modul3
{
    [Serializable]
    public class SysConstrMy
    {
        #region privatne atributy
        private int piId;
        private string psNazov;
        private SysConstrTypes pkTyp;
        private List<int> paZdrojeoveStlpce;
        private List<int> paReferencovaneStlpce;
        #endregion


        #region property
        /// <summary>
        /// unikatne id (v ramci celeho systemu - vsetkych databaz)
        /// kazde dalsie je o jedna vacsie.
        /// </summary>
        public int iId
        {
            get { return piId; }
            set { piId = value; }
        }

        public string sNazov
        {
            get { return psNazov; }
            set { psNazov = value; }
        }

        public SysConstrTypes kTyp
        {
            get { return pkTyp; }
            set { pkTyp = value; }
        }

        public List<int> aZdrojeoveStlpce
        {
            get { return paZdrojeoveStlpce; }
            set { paZdrojeoveStlpce = value; }
        }

        public List<int> aReferencovaneStlpce
        {
            get { return paReferencovaneStlpce; }
            set { paReferencovaneStlpce = value; }
        }
        #endregion


        #region metody
        public SysConstrMy(string pa_sNazov, SysConstrTypes pa_kTyp, List<int> pa_aZdrojeoveStlpce, List<int> pa_aReferencovaneStlpce, int pa_iId)
        {
            this.iId = pa_iId;
            this.kTyp = pa_kTyp;
            this.aZdrojeoveStlpce = pa_aZdrojeoveStlpce;
            this.aReferencovaneStlpce = pa_aReferencovaneStlpce;
            if (pa_sNazov.Equals(""))
            {
                sNazov = this.VygenerujNazov();
            }
            else
            {
                sNazov = pa_sNazov + "_" + kTyp.ToString()  + "_" + pa_iId.ToString();
            }
        }

        private string VygenerujNazov()
        {
            return "c_" + kTyp.ToString() + "_" + iId;
        }

        override
        public string ToString()
        {
            string stlpceZdrojove = "";
            foreach (int col in aZdrojeoveStlpce)
            {
                stlpceZdrojove += col.ToString() + " ";
            }

            string stlpceReferencovane = "";
            foreach (int col in aReferencovaneStlpce)
            {
                stlpceReferencovane += col.ToString() + " ";
            }
            return sNazov + " (" + stlpceZdrojove + " --> " + stlpceReferencovane + ")";
        }
        #endregion
    }
}
